package com.gray.serverclientuser.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created on 2019/6/22.
 *
 * @author Grak
 * @since 1.0
 */
@RestController
@RefreshScope
@DefaultProperties(defaultFallback = "defaultFallback")
public class UserMsgControllerBase {

    @Value("${server.port}")
    private int port;

    @Value("${msg.name}")
    private String msg;

    //    @HystrixCommand(fallbackMethod = "fallback")
    @RequestMapping("/findByIdBase")
    @HystrixCommand
    public String findById(@RequestBody int id) {

        if (id == 1) {
            return "李斯";
        } else if (id == 2) {
            return "宙斯";
        }
        int ss = 2 / 0;
        return "没有找到！！";
    }

    @RequestMapping("/portBase")
    @HystrixCommand
    public String getPort() {
        return "order-port:" + port + "msg:" + msg;
    }

//    private String fallback(@RequestBody int id) {
//        return "太拥挤了, 请稍后再试~~" + id;
//    }

    private String defaultFallback() {
        return "默认提示：太拥挤了, 请稍后再试~~";
    }
}
